package com.asj.house.controller;


import com.asj.house.client.HouseRoomClient;
import com.asj.house.returns.RespEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 房屋信息表 前端控制器
 * </p>
 *
 * @author asj
 * @since 2021-03-04
 */
@RestController
@RequestMapping("/house-room")
@Slf4j
@Api(value = "房源相关接口", tags = "房源相关接口")
public class HouseRoomController {

    @Resource
    private HouseRoomClient houseRoomClient;

    @ApiOperation(value = "房源列表")
    @GetMapping("/list")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "pageNum", value = "当前页数", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "pageSize", value = "每页数量", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "content", value = "搜索内容", required = false)
    })
    public RespEntity listHouseRoom(@RequestParam(value = "pageNum", required = true) Integer pageNum,
                                    @RequestParam(value = "pageSize", required = true) Integer pageSize,
                                    @RequestParam(value = "content", required = false) String content) {
        RespEntity respEntity = new RespEntity();
        if (StringUtils.isBlank(content)) {
            respEntity = houseRoomClient.listHouseRoom(pageNum, pageSize);
        }else {
            respEntity = houseRoomClient.searchHouseRoom(pageNum, pageSize, content);
        }
        return respEntity;
    }

    @ApiOperation(value = "房源分类")
    @GetMapping("/type")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "pageNum", value = "当前页数", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "pageSize", value = "每页数量", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "type", value = "房源类型（1=复式，2=别墅，3=园景房，4=阁楼，5=单元式，6=公寓式）", required = true)
    })
    public RespEntity typeHouseRoom(@RequestParam(value = "pageNum", required = true) Integer pageNum,
                                    @RequestParam(value = "pageSize", required = true) Integer pageSize,
                                    @RequestParam(value = "type", required = true) Integer type) {
        RespEntity respEntity = houseRoomClient.typeHouseRoom(pageNum, pageSize, type);
        return respEntity;
    }

    @ApiOperation(value = "房源城市分布")
    @GetMapping("/city")
    @ApiImplicitParam(paramType = "query", dataType = "String", name = "city", value = "城市名称", required = true)
    public RespEntity listCityRoom(@RequestParam(value = "city", required = true) String city) {
        RespEntity respEntity = houseRoomClient.listCityRoom(city);
        return respEntity;
    }

    @GetMapping("/same")
    @ApiOperation(value = "同城房源信息")
    @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "roomId", value = "房源id", required = true)
    public RespEntity sameCityRoom(@RequestParam(value = "roomId", required = true) Integer roomId) {
        RespEntity respEntity = houseRoomClient.sameCityRoom(roomId);
        return respEntity;
    }

    @ApiOperation(value = "按日期搜索房源")
    @GetMapping("/search")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "begin", value = "租房日期", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "end", value = "退房日期", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "num", value = "可住人数", required = true)
    })
    public RespEntity searchDate(@RequestParam(value = "begin", required = true) String begin,
                                 @RequestParam(value = "end", required = true) String end,
                                 @RequestParam(value = "num", required = true) Integer num) {
        RespEntity respEntity = houseRoomClient.searchRoomByDate(begin, end, num);
        return respEntity;
    }
}
